package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级", description = "提供护理项目的CRUD操作")
public class NursingLevelController extends BaseController{
    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 获取所有护理等级
     * @return
     */
    @GetMapping("/listAll")
    @ApiOperation(value = "获取所有护理等级")
    public ResponseResult getAll() {
        return ResponseResult.success(nursingLevelService.getAll());
    }

    /**
     * 新增护理等级
     * @param project
     * @return
     */
    @PostMapping("/insert")
    @ApiOperation(value = "新增护理等级")
    public ResponseResult add(
            @RequestBody NursingLevelDto project) {
        return toAjax(nursingLevelService.add(project));
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @param name
     * @param status
     * @return
     */
    @GetMapping("/listByPage")
    @ApiOperation(value = "分页查询")
    public ResponseResult selectByPage(Integer pageNum, Integer pageSize, String name, Integer status){
        // 实现分页查询的逻辑
        return ResponseResult.success(nursingLevelService.selectByPage(pageNum, pageSize, name, status));
    }

    /**
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取护理等级")
    public ResponseResult get(@PathVariable Long id) {
        return ResponseResult.success(nursingLevelService.getById(id));
    }

    /**
     * 更新护理等级
     * @param project
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "更新护理等级", notes = "根据ID更新护理项目")
    public ResponseResult update( @RequestBody NursingLevelDto project) {
        return toAjax( nursingLevelService.updateById(project));
    }

    /**
     * 删除护理等级
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除护理等级", notes = "根据ID删除护理项目")
    public ResponseResult delete(@PathVariable Long id) {
        return  toAjax(nursingLevelService.removeById(id)) ;
    }

    /**
     * 修改状态
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "更改护理计划状态")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        return toAjax(nursingLevelService.updateStatus(id, status));
    }

}
